package com.zh;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
public class Insert {
	private SessionFactory sFactory;
	private Util util;
	
	
	public SessionFactory getsFactory() {
		return sFactory;
	}
	public void setsFactory(SessionFactory sFactory) {
		this.sFactory = sFactory;
	}
	public Util getUtil() {
		return util;
	}
	public void setUtil(Util util) {
		this.util = util;
	}
	
	public void insertTable(String tablename,Object object){
		Session session=sFactory.openSession();
		Transaction transaction=session.beginTransaction();
		if(tablename.equals("user")){
			User user=(User)object;
			session.save(user);
		}
		else if(tablename.equals("house")){
			House house=(House)object;
			session.save(house);
		}
		else if(tablename.equals("repair")){
			Repair repair=(Repair)object;
			session.save(repair);
		}
		else if(tablename.equals("payment")){
			Payment payment=(Payment)object;
			session.save(payment);
		}
		else if(tablename.equals("level")){
			Level level=(Level)object;
			session.save(level);
		}
		else if(tablename.equals("message")){
			Message message=(Message)object;
			session.save(message);
		}
		transaction.commit();
		session.close();
	}

	
	
}
